package com.qidian.common.beanCache;

import java.util.concurrent.ConcurrentHashMap;

import com.qidian.common.beans.AccountBean;

public final class AccountBeanCache
{    
	private static AccountBeanCache AccountBeanCache = new AccountBeanCache() ;
    
	/*	<注册码,账户>	*/
	public ConcurrentHashMap<String,AccountBean> buffer  ;
	/*	<账号ID,账户>	*/
	public ConcurrentHashMap<Long,AccountBean> buf  ;
	
    private AccountBeanCache()
    {
    	buffer = new ConcurrentHashMap<String,AccountBean>(1024) ;
    	buf = new ConcurrentHashMap<Long,AccountBean>(1024) ;
    }
    
    public static AccountBeanCache getInstance()
    {
    	return AccountBeanCache ;
    }
    
    public void add(AccountBean AccountBean)
    {
    	if (AccountBean == null)
    		return ;
    	buffer.put(AccountBean.getAccount().toLowerCase(), AccountBean) ;
    	buf.put(AccountBean.getAccountId(), AccountBean) ;
    }
    /**
     * 根据注册码获取子账号
     * 
     * */
    public AccountBean get(String maskCode)
    {
    	if (maskCode == null)
    		return null ;
    	return buffer.get(maskCode.toLowerCase()) ;
    }
    
    
//    /**
//     * 用户点数是否充足。
//     * 
//     * */
//	public boolean checkPoint(String maskCode, int point) 
//	{
//		AccountBean AccountBean = get(maskCode) ;
//		if (AccountBean == null)
//			return false ;
//		return AccountBean.getPoint()-AccountBean.getUsedPoint() >= point;
//	}
    
//    public boolean isValid(String account)
//    {
//    	if (account == null)
//    		return false ;
//    	return buffer.containsKey(account.toLowerCase()) ;
//    }

    /**
     * 根据ID获取子账号
     * 
     * */
	public AccountBean get(Long accountId) 
	{
		return buf.get(accountId) ;
	}

	public Object size() 
	{
		return buf.size();
	}

}
